<?php
use yii\helpers\Url;
?>
<div style="background: #2DAD5E;text-align: center;height: 2rem;line-height: 2rem;color: #fff">

    <p>可回收垃圾回收登记</p>

</div>
<form action="<?=Url::to(['site/create-order'])?>" method="post">
<div class="weui-cells">
    <div class="weui-cell" style="position: relative">
        <div class="weui-cell__hd" style="width: 25%"><label class="weui-label"><img style="width: 17px;display: inline;position: relative;top:2px" src="/assets/img/our.png">户号</label></div>
        <div class="weui-cell__bd" >
            <input class="weui-input" id="customerId" name="customerId" placeholder="请输入户号或点击扫描">
            <img src="/assets/img/scan.png" style="width: 1.3rem;position: absolute;top:0.5rem;right: 0.1rem">
        </div>
    </div>
</div>
<br />
<a href="javascript:;" id="add" style="background: #2DAD5E;width: 90%" class="weui-btn weui-btn_primary">添加</a>
<div id="customerList"></div>
<script>
    $("#add").click(function () {
        var id= $("#customerId").val();
        $.ajax({
            url:"<?=Url::to(['site/get-customer-info'])?>",
            data:"customerId="+id,
            type:'post',
            dataType:"json",
            success:function (data) {
                if(data.status){
                    var dom = " <div><div class=\"weui-cells\">\n" +
                        "        <a class=\"weui-cell weui-cell_access\" href=\"javascript:;\">\n" +
                        "            <div class=\"weui-cell__bd\" style=\"overflow: hidden\">\n" +
                        "                <p><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/address.png\">\n" +
                        data.info.realname+" "+data.info.address+
                        "                    </p>\n" +
                        "            </div>\n" +
                        "            <div class=\"weui-cell__ft\">\n" +
                        "            </div>\n" +
                        "        </a>\n" +
                        "    </div>\n" +
                        "    <div class=\"weui-form-preview info_cell\" style=\"display:none\" > \n" +
                        "        <div class=\"weui-form-preview__hd\">\n" +
                        "            <label class=\"weui-form-preview__label\">户主姓名</label>\n" +
                        "            <em class=\"weui-form-preview__value\">"+data.info.realname+"</em>\n" +
                        "        </div>\n" +
                        "        <div class=\"weui-form-preview__bd\">\n" +
                        "            <div class=\"weui-form-preview__item\">\n" +
                        "                <label class=\"weui-form-preview__label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/tel.png\">电话</label>\n" +
                        "                <span class=\"weui-form-preview__value\" >"+data.info.phone+"</span>\n" +
                        "            </div>\n" +
                        "            <div class=\"weui-form-preview__item\">\n" +
                        "                <label class=\"weui-form-preview__label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/address.png\">住址</label>\n" +
                        "                <span class=\"weui-form-preview__value\" >"+data.info.address+"</span>\n" +
                        "            </div>\n" +
                        "            <div class=\"weui-form-preview__item\">\n" +
                        "                <label class=\"weui-form-preview__label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/blue.png\">蓝积分</label>\n" +
                        "                <span class=\"weui-form-preview__value\" >"+data.info.blue+"</span>\n" +
                        "            </div>\n" +
                        "            <div class=\"weui-form-preview__item\">\n" +
                        "                <label class=\"weui-form-preview__label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/green.png\">绿积分</label>\n" +
                        "                <span class=\"weui-form-preview__value\" >"+data.info.green+"</span>\n" +
                        "            </div>\n" +
                        "\n" +
                        "        </div>\n" +
                        "\n" +
                        "    </div>" + "<input name=\"customer[]\" type='hidden' value='"+data.info.id+"'></div>";
                    $("#customerList").append(dom)
                }else{
                    alert(data.msg);
                }
            }
        })
    })

    $("div").on("click",".weui-cell_access",function () {

        $(this).parent().parent().find(".info_cell").toggle();
    })
</script>
<br>
<div id="item">

        <input name="_csrf-frontend" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
<div class="relative item">
<div class="weui-cells weui-cells_form width90">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label"><img style="width: 17px;display: inline;position: relative;top:2px" src="/assets/img/cate.png">品类</label></div>
        <div class="weui-cell__bd">
            <select class="weui-select" name="list[1][cate]">
               <?php foreach ($cates as $cate){?>
                   <option value="<?=$cate['id']?>"><?=$cate['name']?></option>
                <?php }?>
            </select>
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd"><label class="weui-label"><img style="width: 17px;display: inline;position: relative;top:2px" src="/assets/img/weight.png">重量</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input weight"  name="list[1][number]" type="number" placeholder="请输入重量">
        </div>
        <div class="weui-cell__ft">
            <span class="weui-vcode-btn">kg</span>
        </div>
    </div>

</div>
    <div class="refuse_del">×</div>
</div>

</div>    </form>
<a href="javascript:;" id="add2" class="weui-btn weui-btn_plain-default width90" style="border:1px solid #2DAD5E;color: #2DAD5E">新增</a>
<br>
<a href="javascript:;" id="submit"  style="background: #2DAD5E" class="weui-btn weui-btn_primary">下一步</a>
<script>
    var no=1;
    $("#submit").click(function() {
        $("form").submit();
    })

    $("#add2").click(function () {
        no++;
        var dom="<div class=\"relative item\">\n" +
            "<div class=\"weui-cells weui-cells_form width90\">\n" +
            "    <div class=\"weui-cell\">\n" +
            "        <div class=\"weui-cell__hd\"><label class=\"weui-label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/cate.png\">品类</label></div>\n" +
            "        <div class=\"weui-cell__bd\">\n" +
            "            <select class=\"weui-select\" name=\"list["+no+"][cate]\" >\n" +
            "<?php foreach ($cates as $cate){
            echo '<option value=\"'.$cate['id'].'\">'.$cate['name'].'</option>';
            }?>"+

            "            </select>\n" +
            "        </div>\n" +
            "    </div>\n" +
            "    <div class=\"weui-cell weui-cell_vcode\">\n" +
            "        <div class=\"weui-cell__hd\"><label class=\"weui-label\"><img style=\"width: 17px;display: inline;position: relative;top:2px\" src=\"/assets/img/weight.png\">重量</label></div>\n" +
            "        <div class=\"weui-cell__bd\">\n" +
            "            <input class=\"weui-input weight\" name=\"list["+no+"][number]\" type=\"number\" placeholder=\"请输入重量\">\n" +
            "        </div>\n" +
            "        <div class=\"weui-cell__ft\">\n" +
            "            <span class=\"weui-vcode-btn\">kg</span>\n" +
            "        </div>\n" +
            "    </div>\n" +
            "\n" +
            "</div>\n" +
            "    <div class=\"refuse_del\">×</div>\n" +
            "</div>";
        $("#item").append(dom);
    })
    $("#item").on("click",".refuse_del",function(){
        $(this).parent().remove();
    })


</script>
